package ntd.util.frame.action.database;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import ntd.action.ActionAbs;
import ntd.action.bo.ActionInfo;
import ntd.action.bo.ActionOutBo;
import ntd.util.UtilCatch;
import ntd.util.frame.data.factory.FactoryData;
import ntd.util.frame.data.tool.ToolMysql;

public class ActionTableInfos extends ActionAbs {

    @Override
    public ActionInfo info() {
        return new ActionInfo("数据表信息查询 - 全部/或指定", "action-table-infos", new ActionTableInfos());
    }

    @Override
    public ActionOutBo handle() {
        

        ToolMysql toolMysql = new ToolMysql(FactoryData.dataSource(actionInBo.dsId()));

        return UtilCatch.tryCatch(() -> {
            String tableName = actionInBo.getDataCode();
            if (StrUtil.equals(tableName, "*")) {
                tableName = null;
            }
            return new ActionOutBo(toolMysql.table(tableName));
        });
    }
}
